<template>
	<view class="header-view" style="width: 100vw;height: 100vh">
		<view 
		style="min-height: 100vh">
		<hx-navbar title="" :back="true" :fixed="false" :color="knavTitleColor" barPlaceholder="hidden" transparent="auto"></hx-navbar>
		<view class="ruleWrap">
			<view class="ruleCont" :style="{color:SelStyle.selectColorSize}" @click="$common.navigateTo('/pages/user/settings/drawAaffle/list')">抽奖记录 </view>
		</view>
		<view class="container">
			<view class="title-item">
				<image class="aff-img" src="/static/user/affle1.png" mode="scaleToFill"></image>
				<image class="num-view" src="/static/user/affle2.png" mode="scaleToFill"></image>
			</view>
			<view class="chou-img cell-item-cc">
				<image src="/static/index/icon-78.png" style="width: 500rpx;height: 500rpx">
				
				<!-- <image src="/static/index/icon-78.png" v-show="!gifFlag" style="width: 500rpx;height: 500rpx">
				</image>
				<image src="/static/index/icon-80.gif" v-show="gifFlag" style="width: 500rpx;height: 500rpx">
				</image> -->
			</view>
			<view class="but-view cell-item-cc" :style="[SelStyle]">
				<view class="but-body-view">
					<view class="title-view">您可抽奖次数：{{list.count}}</view>
					<view class="alternative-1" v-if="true">
						<view class="but-view-1 cell-item-cc m-t-20" :style="{background:SelStyle.buttonBcak}" @click="getStoveData">
							<template v-if="!gifFlag">
								开始抽奖
							</template>
							<template v-else>
								<text class="u-m-r-10">抽奖中</text>
								<view class="loading"></view>
							</template>
						</view>
					</view>
				</view>
			</view>
			<!-- 			<view class="cell-item-cb m-t-20 item">
				<view class="btn-item1">
					剩余抽奖次数:{{list.count}}
				</view>
				<view class="btn-item" @click="$common.navigateTo('/pages/user/settings/drawAaffle/list')">
					查看抽奖记录
				</view>

			</view> -->
			<view class="rule-title">
				<view class="text">抽奖规则</view>
			</view>
			<view class="guize">
				<jshopContent :content="list.content" v-if="list.content"></jshopContent>
			</view>
		</view>
		<uni-popup ref="rewards" type="center" :isMaskClick="false">
			<view class="rewards_box">
				<view class="rewards_title">恭喜获得新版权</view>
				<image v-if='Jlist.id!="未中奖"' src="/static/user/rewards_light.png" mode="widthFix"
					class="rewards_light"></image>
				<image :src="Jlist.image" mode="aspectFill" class="reward_img"></image>
				<view class="reward_name">
					{{Jlist.name}}
				</view>
			</view>
			<view class="confirm_btn2 " @tap="confirm">确定</view>
		</uni-popup>
	</view>
	</view>
</template>

<script>
	import AlmostLottery from '@/uni_modules/almost-lottery/components/almost-lottery/almost-lottery.vue'
	import popup from '@/uni_modules/uni-popup/components/uni-popup/popup.js'
	import jshopContent from '@/components/jshop/jshop-content.vue' //视频和文本解析组件
	export default {
		components: {
			jshopContent
		},
		data() {
			return {
				SelStyle:{
					// 浅色单个背景颜色
					'--QianmenonlyBackgournd':this.$store.state.QianmenonlyBackgournd,
					 buttonBcak:this.$store.state.buttonBcak,//渐变按钮颜色
					 selectColorSize:this.$store.state.selectColorSize,//字体颜色
				},
				list: [],
				gifFlag: false,
				Jlist: {},
				prizeList: [{
					id: 1,
					prizeName: '',
					prizeImage: ''
				}],

				prizeIndex: -1,

			}
		},
		//下拉
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 200)
				this.get_stoveList()
		},
		onShow() {
			this.get_stoveList()
		},
		methods: {
			confirm: function() {
				this.Jlist = {};
				this.get_stoveList()
				this.$refs.rewards.close();

			},
			get_addmaterial(id) {
				this.$api.addmateriall({
					id: id
				}, res => {
					if (res.status) {
						this.Jlist = res.data
						this.$refs.rewards.open();
						// let id = res.data.id
						// for (let i = 0; i < this.prizeList.length; i++) {
						// 	let item = this.prizeList[i]
						// 	if (item.id === id || item.id == '未中奖') {
						// 		// 中奖下标
						// 		this.prizeIndex = i
						// 		break
						// 	}
						// }

					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			get_stoveList() {
				this.$api.stoveList({}, res => {
					if (res.status) {
						this.prizeList = res.data.get
						this.list = res.data

					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			// 本次抽奖开始
			getStoveData() {
				console.log('本次抽奖开始')
				if (this.list.count > 0) {

					if (this.gifFlag) {
						return;
					}
					this.gifFlag = true;
					setTimeout(() => {
						this.gifFlag = false;
						this.get_addmaterial(this.list.prizeId)
					}, 4000);

				} else {
					this.$common.errorToShow('次数不足')
				}


			},
			// 本次抽奖结束
			handleDrawEnd() {
				this.$refs.rewards.open()
				return
			},

		}
	}
</script>

<style lang="scss" scoped>
	.ruleWrap {
		width: 123rpx;
		height: 44rpx;
		position: absolute;
		top: calc(var(--status-bar-height) + 82rpx);
		right: 0;
		z-index: 20;
		.ruleCont {
			width: 100%;
			height: 100%;
			background-color: #F6BCA9;
			border-radius: 200rpx 0 0 200rpx;
			padding-left: 20rpx;
			line-height: 44rpx;
			font-size: 22rpx;
			// color: #D5573D;
			font-weight: 400;
			position: relative;
			z-index: 2;
		}
	}
	.ruleWrap::after {
		display: block;
		clear: both;
		content: '';
		width: 100%;
		height: 100%;
		border-radius: 200rpx 0 0 200rpx;
		background-color: #E85D3F;
		position: absolute;
		left: 0;
		bottom: -2rpx;
		z-index: 1;
	}
	.container {
		padding: 0 30rpx;
		z-index: 3;
		.but-view {
			width: 100%;
			height: 249rpx;
			
			// background-color: #FF5B6C;
			background-color: var(--QianmenonlyBackgournd);
			border-radius: 20rpx;
			padding: 25rpx;
			border: 1rpx solid #FCC9CB;
			margin: 63rpx 0 44rpx;
			.but-body-view {
				height: 100%;
				width: 100%;
				background-color: #fff;
				border-radius: 20rpx;
				padding-top: 28rpx;
				.alternative-1 {
					width: 100%;
					display: flex;
					justify-content: space-around;
					align-items: center;
					.but-view-1 {
						width: 239rpx;
						height: 59rpx;
						// background-color: #E85D3F;
						border-radius: 50rpx;
						color: #fff;
						font-size: 32rpx;
						font-weight: bold;
						.loading {
							width: 30rpx;
							height: 30rpx;
							border-radius: 50%;
							border: 5rpx solid #BEBEBE;
							border-left: 5rpx solid #2979ff;
							animation: load 1s linear infinite;
							margin-left: 10rpx;
						}

						@keyframes load {
							from {
								transform: rotate(0deg);
							}

							to {
								transform: rotate(360deg);
							}
						}
					}
				}

				.title-view {
					text-align: center;
					color: #000000;
					font-size: 30rpx;
					font-weight: bold;
				}
			}
		}

		.guize {
			width: 640;
			min-height: 320rpx;
			padding: 46rpx 30rpx;
			background-color: #fff;
			border-radius: 20rpx;
			position: relative;
			z-index: 2;
			font-size: 24rpx;
			color: #000;
			line-height: 40rpx;
			margin: 24rpx auto 0;
		}

		.rule-title {
			text-align: center;
			.text {
				display: inline-block;
				font-size: 32rpx;
				color: #333;
				font-weight: bold;
				position: relative;
			}
			.text::after, .text::before {
				display: block;
				clear: both;
				content: '';
				width: 12rpx;
				height: 12rpx;
				border-radius: 50%;
				background-color: #333;
				position: absolute;
				top: 50%;
				left: -25rpx;
				transform: translateY(-50%);
			}
			.text::before {
				left: auto;
				right: -25rpx;
			}
		}

		.item {
			padding: 20rpx 60rpx;

			.btn-item1 {
				color: #6FEFEC !important;
				border: 2rpx solid #6FEFEC;
			}

			.btn-item,
			.btn-item1 {
				color: $text-zdy;
				border-radius: 50rpx;
				width: 300rpx;

				text-align: center;
				padding: 10rpx 0;
				font-size: 24rpx;

				border: 2rpx solid $text-zdy;
			}

		}

		.title-item {
			padding: 65rpx 0 26rpx;
			position: relative;
			.aff-img {
				width: 478rpx;
				height: 79rpx;
				display: block;
				margin: 0 auto 35rpx;
			}
			.num-view {
				width: 299rpx;
				height: 84rpx;
				display: block;
				margin: 0 auto;
			}
		}

	}
</style>